﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>Light: Test/LightTestMoq/LightTestMoq.cs Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                C# examples using state machines generated by StateBuilderDotNet
            </h1>
            <h3>
                Light: Test/LightTestMoq/LightTestMoq.cs Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">Test/LightTestMoq/LightTestMoq.cs</div>  </div>
</div>
<div class="contents">
<a href="_light_test_moq_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿using System;
<a name="l00002"></a>00002 <span class="keyword">using</span> System.Collections.Generic;
<a name="l00003"></a>00003 <span class="keyword">using</span> System.Linq;
<a name="l00004"></a>00004 <span class="keyword">using</span> System.Text;
<a name="l00005"></a>00005 <span class="keyword">using</span> NUnit.Framework;
<a name="l00006"></a>00006 <span class="keyword">using</span> StateForge.StateMachine;
<a name="l00007"></a>00007 <span class="keyword">using</span> Moq;
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="keyword">namespace </span>StateForge.Examples.Light
<a name="l00010"></a>00010 {
<a name="l00011"></a>00011     [TestFixture]
<a name="l00012"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html">00012</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html">LightTestMoq</a>
<a name="l00013"></a>00013     {
<a name="l00014"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#a606f5b858c86c56d2e325748b71f8aed">00014</a>         <span class="keyword">private</span> LightContext <a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#a606f5b858c86c56d2e325748b71f8aed">lightContext</a>;
<a name="l00015"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#ad8ece8fe15be065d518314745936d3c0">00015</a>         <span class="keyword">private</span> Mock&lt;ILightActuator&gt; <a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#ad8ece8fe15be065d518314745936d3c0">mockLightActuator</a>;
<a name="l00016"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#a6dbdd257b969c2fc774a8a3261d05b99">00016</a>         <span class="keyword">private</span> Mock&lt;IObserver&gt; <a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#a6dbdd257b969c2fc774a8a3261d05b99">mockObserver</a>;
<a name="l00017"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#ad71dade4b292a71a2ba9d2cb02b2df01">00017</a>         <span class="keyword">private</span> String contextName = <span class="stringliteral">&quot;LightContext&quot;</span>;
<a name="l00018"></a>00018 
<a name="l00019"></a>00019         [SetUp]
<a name="l00020"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#a51f4367c886d77f8e70965dd19d6d617">00020</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Setup()
<a name="l00021"></a>00021         {
<a name="l00022"></a>00022             mockLightActuator = <span class="keyword">new</span> Mock&lt;ILightActuator&gt;();
<a name="l00023"></a>00023             mockObserver = <span class="keyword">new</span> Mock&lt;IObserver&gt;();
<a name="l00024"></a>00024             lightContext = <span class="keyword">new</span> LightContext(mockLightActuator.Object);
<a name="l00025"></a>00025             lightContext.Observer = mockObserver.Object;
<a name="l00026"></a>00026         }
<a name="l00027"></a>00027 
<a name="l00028"></a>00028         [Test]
<a name="l00029"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#a960502c30c8804dcff76d224f36385fc">00029</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Void()
<a name="l00030"></a>00030         {
<a name="l00031"></a>00031             mockLightActuator.Verify(la =&gt; la.DoOn(), Times.Exactly(0));
<a name="l00032"></a>00032             mockLightActuator.Verify(la =&gt; la.DoOff(), Times.Exactly(0));
<a name="l00033"></a>00033             mockObserver.Verify(observer =&gt; observer.OnTransitionBegin(It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;()), Times.Exactly(0));
<a name="l00034"></a>00034             mockObserver.Verify(observer =&gt; observer.OnTransitionEnd(It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;()), Times.Exactly(0));
<a name="l00035"></a>00035             mockObserver.Verify(observer =&gt; observer.OnEntry(It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;()), Times.Exactly(0));
<a name="l00036"></a>00036             mockObserver.Verify(observer =&gt; observer.OnExit(It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;()), Times.Exactly(0)); 
<a name="l00037"></a>00037         }
<a name="l00038"></a>00038 
<a name="l00039"></a>00039         [Test]
<a name="l00040"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#aca8181167e64e42b7211347639a35cc6">00040</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> On()
<a name="l00041"></a>00041         {
<a name="l00042"></a>00042             <span class="comment">//Needed when Strict mode is used</span>
<a name="l00043"></a>00043             <span class="comment">//mockLightActuator.Setup(la =&gt; la.DoOn());</span>
<a name="l00044"></a>00044             <span class="comment">//mockObserver.Setup(observer =&gt; observer.OnTransitionBegin(contextName, It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;()));</span>
<a name="l00045"></a>00045             <span class="comment">//mockObserver.Setup(observer =&gt; observer.OnExit(contextName, It.IsAny&lt;string&gt;()));</span>
<a name="l00046"></a>00046             <span class="comment">//mockObserver.Setup(observer =&gt; observer.OnEntry(contextName, It.IsAny&lt;string&gt;()));</span>
<a name="l00047"></a>00047             <span class="comment">//mockObserver.Setup(observer =&gt; observer.OnTransitionEnd(contextName, It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;()));</span>
<a name="l00048"></a>00048 
<a name="l00049"></a>00049             lightContext.EvOn();
<a name="l00050"></a>00050             
<a name="l00051"></a>00051             mockLightActuator.Verify(la =&gt; la.DoOn(), Times.Exactly(1));
<a name="l00052"></a>00052             mockLightActuator.Verify(la =&gt; la.DoOff(), Times.Exactly(0));
<a name="l00053"></a>00053             mockObserver.Verify(observer =&gt; observer.OnTransitionBegin(contextName, It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;()), Times.Exactly(1));
<a name="l00054"></a>00054             mockObserver.Verify(observer =&gt; observer.OnExit(contextName, It.IsAny&lt;<span class="keywordtype">string</span>&gt;()), Times.Exactly(1));
<a name="l00055"></a>00055             mockObserver.Verify(observer =&gt; observer.OnEntry(contextName, It.IsAny&lt;<span class="keywordtype">string</span>&gt;()), Times.Exactly(1));
<a name="l00056"></a>00056             mockObserver.Verify(observer =&gt; observer.OnTransitionEnd(contextName, It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;(), It.IsAny&lt;<span class="keywordtype">string</span>&gt;()), Times.Exactly(1));
<a name="l00057"></a>00057         }
<a name="l00058"></a>00058 
<a name="l00059"></a>00059         [Test]
<a name="l00060"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#aa8903ea5970f4909f2cb8f0d19e1c9ae">00060</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> OnOff()
<a name="l00061"></a>00061         {
<a name="l00062"></a>00062             lightContext.EvOn();
<a name="l00063"></a>00063             lightContext.EvOff();
<a name="l00064"></a>00064             mockLightActuator.Verify(la =&gt; la.DoOn(), Times.Exactly(1));
<a name="l00065"></a>00065             mockLightActuator.Verify(la =&gt; la.DoOff(), Times.Exactly(1));
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067 
<a name="l00068"></a>00068         [Test]
<a name="l00069"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#adacc5638cea5f6024c264399867d177f">00069</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Off()
<a name="l00070"></a>00070         {
<a name="l00071"></a>00071             lightContext.EvOff();
<a name="l00072"></a>00072             mockLightActuator.Verify(la =&gt; la.DoOff(), Times.Exactly(0));
<a name="l00073"></a>00073         }
<a name="l00074"></a>00074 
<a name="l00075"></a>00075         [Test]
<a name="l00076"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#a00851e52645e5725fefef9a01435762a">00076</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> OffOnOnOffOff()
<a name="l00077"></a>00077         {
<a name="l00078"></a>00078             lightContext.EvOff();
<a name="l00079"></a>00079             lightContext.EvOn();
<a name="l00080"></a>00080             lightContext.EvOn();
<a name="l00081"></a>00081             lightContext.EvOff();
<a name="l00082"></a>00082             lightContext.EvOff();
<a name="l00083"></a>00083             mockLightActuator.Verify(la =&gt; la.DoOn(), Times.Exactly(1));
<a name="l00084"></a>00084             mockLightActuator.Verify(la =&gt; la.DoOff(), Times.Exactly(1));
<a name="l00085"></a>00085         }
<a name="l00086"></a>00086 
<a name="l00087"></a>00087         [Test]
<a name="l00088"></a><a class="code" href="class_state_forge_1_1_examples_1_1_light_1_1_light_test_moq.html#a959cadb4236844e2da962c53321aa74b">00088</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> OnOffOnOff()
<a name="l00089"></a>00089         {
<a name="l00090"></a>00090             lightContext.EvOn();
<a name="l00091"></a>00091             lightContext.EvOff();
<a name="l00092"></a>00092             lightContext.EvOn();
<a name="l00093"></a>00093             lightContext.EvOff();
<a name="l00094"></a>00094             mockLightActuator.Verify(la =&gt; la.DoOn(), Times.Exactly(2));
<a name="l00095"></a>00095             mockLightActuator.Verify(la =&gt; la.DoOff(), Times.Exactly(2));
<a name="l00096"></a>00096         }
<a name="l00097"></a>00097     }
<a name="l00098"></a>00098 }
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
